home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performAlignObjects.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  6.7 KB  |  250 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Procedure Name:
  19. //      performAlignObjects
  20. //
  21. //  Description:
  22. //        
  23. //         
  24. //  Input Arguments:
  25. //        $option : Whether to set the options to default values.
  26. //  Return Value:
  27. //        command string iff $option==2
  28. //
  29.  
  30. //
  31. // Initialize optionVars for align:
  32. // 
  33. proc setOptionVars (
  34.     string        $prefix, 
  35.     int            $forceFactorySettings
  36. )
  37. {
  38.     string $varName;
  39.     string $toggles[]  = {"atl", "axisX", "axisY", "axisZ"};
  40.     int    $defaults[] = {0, 1, 0, 0};
  41.     int    $i;
  42.  
  43.     for ($i = size($defaults) ; $i-- ; )
  44.     {
  45.         $varName = ($prefix + $toggles[$i]);
  46.         if ($forceFactorySettings || !`optionVar -exists $varName`)
  47.             optionVar -intValue $varName $defaults[$i];
  48.     }
  49.  
  50.     $varName = ($prefix + "mode");
  51.     if ($forceFactorySettings || !`optionVar -exists $varName`)
  52.         optionVar -stringValue $varName "Mid";
  53. }
  54.  
  55. global proc updateAlignMode(string $value)
  56. {
  57.     string $prefix = "align";
  58.     string $strIcons[] = {"Min", "Mid", "Max", "Dist", "Stack"};
  59.     string $varName = $prefix;
  60.  
  61.     for ($j= size($strIcons) ; $j-- ; )
  62.     {
  63.         if ($strIcons[$j] == $value)
  64.             symbolCheckBox -e -v true ($varName+$strIcons[$j]);
  65.         else
  66.             symbolCheckBox -e -v false ($varName+$strIcons[$j]);
  67.     }
  68.  
  69.     if (($value == "Dist") || ($value == "Stack"))
  70.         optionMenuGrp -e -en 0 ($prefix+"atl");
  71.     else
  72.         optionMenuGrp -e -en 1 ($prefix+"atl");
  73.         
  74. }
  75.  
  76. global proc performAlignObjectsSetup (string $parent, int $forceFactSettings)
  77. {
  78.     string $prefix = "align";
  79.  
  80.     setOptionVars($prefix, $forceFactSettings);
  81.     setParent $parent;
  82.     
  83.     string $varName = ($prefix + "atl");
  84.     int $ival = `optionVar -q $varName`;
  85.     if ($ival)
  86.         optionMenuGrp -e -select 2 $varName;
  87.     else
  88.         optionMenuGrp -e -select 1 $varName;
  89.  
  90.     $varName = $prefix + "mode";
  91.     updateAlignMode(`optionVar -query $varName`);
  92.  
  93.     $varName = $prefix + "axis";
  94.     checkBoxGrp -e -v1 `optionVar -query ($varName+"X")` $varName;
  95.     checkBoxGrp -e -v2 `optionVar -query ($varName+"Y")` $varName;
  96.     checkBoxGrp -e -v3 `optionVar -query ($varName+"Z")` $varName;
  97. }
  98.  
  99. global proc performAlignObjectsCallback (string $parent, int $doIt)
  100. {
  101.     string $prefix = "align";
  102.     string $strIcons[] = {"Min", "Mid", "Max", "Dist", "Stack"};
  103.     int $i;
  104.     int $j;
  105.  
  106.     setParent $parent;
  107.  
  108.     string $varName = $prefix + "atl";
  109.     int $ival = `optionMenuGrp -q -select $varName`;
  110.     if ($ival == 2)
  111.         optionVar -intValue $varName 1;
  112.     else
  113.         optionVar -intValue $varName 0;
  114.     
  115.     for ($j= size($strIcons) ; $j-- ; )
  116.         if (`symbolCheckBox -q -v ($prefix+$strIcons[$j])`)
  117.         {
  118.             optionVar -stringValue ($prefix+"mode") $strIcons[$j];
  119.             break;
  120.         }
  121.     string $varName = $prefix+"axis";
  122.     optionVar -intValue ($varName+"X") `checkBoxGrp -q -v1 $varName`;
  123.     optionVar -intValue ($varName+"Y") `checkBoxGrp -q -v2 $varName`;
  124.     optionVar -intValue ($varName+"Z") `checkBoxGrp -q -v3 $varName`;
  125.  
  126.     if ($doIt) 
  127.     {
  128.         performAlignObjects 0;
  129.         addToRecentCommandQueue "performAlignObjects 0" "align";
  130.     }
  131. }
  132.  
  133. proc AlignObjectsOptions (string $prefix)
  134. {
  135.     string $commandName = "performAlignObjects";
  136.     string $callback = ($commandName + "Callback");
  137.     string $setup = ($commandName + "Setup");
  138.  
  139.     string $strIcons[] = {"Min", "Mid", "Max", "Dist", "Stack"};
  140.     string $tips[] = {
  141.         "Align objects' bounding boxes to the minimum value",
  142.         "Align objects' bounding boxes to the middle value",
  143.         "Align objects' bounding boxes to the maximum value",
  144.         "Evenly distribute space between objects' bounding boxes",
  145.         "Align objects' bounding boxes adjacently"};
  146.  
  147.     string $layout = getOptionBox();
  148.     setParent $layout;
  149.     setUITemplate -pushTemplate DefaultTemplate;
  150.     waitCursor -state 1;
  151.     
  152.     string $parent = `columnLayout -adjustableColumn 1`;
  153.  
  154.     rowColumnLayout -nc (1+size($strIcons))
  155.         -cw 1 165 -cw 2 40 -cw 3 40 -cw 4 40 -cw 5 40 -cw 6 40;
  156.             
  157.     text -al "right" -l "Align Mode :";
  158.     for ($j = 0 ; $j < size($strIcons) ; $j++ )
  159.     {
  160.         symbolCheckBox
  161.             -cc ("updateAlignMode "+$strIcons[$j])
  162.             -oni ("alignOn"+$strIcons[$j]+".xpm") 
  163.             -ofi ("align"+$strIcons[$j]+".xpm") 
  164.             -ann $tips[$j]
  165.             ($prefix+$strIcons[$j]);
  166.     }
  167.     
  168.     text -al "right" -l "";
  169.     for ($j = 0 ; $j < size($strIcons) ; $j++ )
  170.     {
  171.         text -al "center" -l $strIcons[$j];
  172.     }
  173.  
  174.     setParent ..;
  175.     separator -h 5 -style "none";
  176.  
  177.     checkBoxGrp -numberOfCheckBoxes 3
  178.         -label "Align In :" -labelArray3 "World X" "World Y" "World Z" 
  179.         ($prefix+"axis");
  180.  
  181.     optionMenuGrp -l "Align to :" ($prefix+"atl");
  182.     menuItem -l "Selection Average";
  183.     menuItem -l "Last Selected Object";
  184.     setParent -m ..;
  185.  
  186.     waitCursor -state 0;
  187.     setUITemplate -popTemplate;
  188.  
  189.     string $applyBtn = getOptionBoxApplyBtn();
  190.     button -edit -label "Align"
  191.            -command ($callback + " " + $parent + " " + 1) $applyBtn;
  192.     string $saveBtn = getOptionBoxSaveBtn();
  193.     button -edit 
  194.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  195.         $saveBtn;
  196.     string $resetBtn = getOptionBoxResetBtn();
  197.     button -edit 
  198.         -command ($setup + " " + $parent + " " + 1) $resetBtn;
  199.  
  200.     setOptionBoxTitle("Align Objects Options");
  201.  
  202.     setOptionBoxHelpTag( "AlignObjectsoptions" );
  203.  
  204.     eval (($setup + " " + $parent + " " + 0));
  205.  
  206.     showOptionBox();
  207. }
  208.  
  209. global proc string performAlignObjects (int $option)
  210. {
  211.     string $prefix = "align";
  212.     string $cmd="";
  213.     switch ($option) 
  214.     {
  215.         case 0:
  216.         setOptionVars($prefix, false);
  217.         $cmd = $prefix;
  218.  
  219.         string $varName = ($prefix + "atl");
  220.         if (`optionVar -q $varName`)
  221.             $cmd = $cmd + " -atl";
  222.  
  223.         $varName = ($prefix + "mode");
  224.         string $val = `optionVar -query $varName`;
  225.  
  226.         $varName = ($prefix + "axisX");
  227.         if (`optionVar -query $varName`)
  228.           $cmd = $cmd + " -x "+ $val;
  229.  
  230.         $varName = ($prefix + "axisY");
  231.         if (`optionVar -query $varName`)
  232.           $cmd = $cmd + " -y "+ $val;
  233.  
  234.         $varName = ($prefix + "axisZ");
  235.         if (`optionVar -query $varName`)
  236.           $cmd = $cmd + " -z "+ $val;
  237.  
  238.         evalEcho($cmd);
  239.         break;
  240.  
  241.         case 1:
  242.             AlignObjectsOptions($prefix);
  243.             break;
  244.         case 2:
  245.             $cmd="performAlignObjects 0";
  246.             break;
  247.     }
  248.     return $cmd;
  249. }
  250.